<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!-- 搜索 -->
      <el-input v-model="query.extractNo" clearable placeholder="提现订单号" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
      <el-input v-model="query.realName" clearable placeholder="真实姓名" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery" />
      <el-select v-model="query.status" clearable placeholder="状态" class="filter-item" style="width: 150px" @change="toQuery">
        <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key" />
      </el-select>
      <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
      <!-- 新增 -->
      <el-button
        type="danger"
        class="filter-item"
        size="mini"
        icon="el-icon-refresh"
        @click="toQuery"
      >刷新</el-button>
    </div>
    <!--表单组件-->
    <eForm ref="form" :is-add="isAdd" />
    <!--表格渲染-->
    <el-table v-loading="loading" :data="data" size="small" style="width: 100%;">
      <!-- <el-table-column prop="id" label="id" /> -->
      <el-table-column prop="extractNo" label="提现订单号" width="150" align="center"/>
      <el-table-column prop="extractPrice" label="提现金额" width="100" align="center"/>
      <el-table-column prop="extractType" label="提现方式" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.extractType=='weixin'">
            姓名:{{ scope.row.realName }}<br>
            微信号:{{ scope.row.wechat }}
          </div>
          <div v-else>
            姓名:{{ scope.row.realName }}<br>
            支付宝号:{{ scope.row.alipayCode }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="addTime" label="申请时间" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.createTime }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="status" label="审核状态" align="center">
        <template slot-scope="scope">
          <div v-if="scope.row.status==1" style="color: #f124c7;">
            <strong>提现中</strong>
          </div>
          <div v-else-if="scope.row.status==-1" style="color: red;">
            <strong>未通过</strong><br>
            {{ scope.row.failTime }}
          </div>
          <div v-else-if="scope.row.status==2" style="color: #409eff;">
            <strong>已到账</strong><br>
            {{scope.row.updateTime }}
          </div>
          <div v-else-if="scope.row.status==3" style="color: red;">
            <strong>提现失败</strong><br>
            {{scope.row.failTime }}
          </div>
          <div v-else style="color: #e6a23c;">
            <strong>待审核</strong>
          </div>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="备注" align="center">
        <template slot-scope="scope">
          <p>{{ scope.row.mark }}</p>
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip label="失败原因" align="center">
        <template slot-scope="scope">
          <p>{{ scope.row.failMsg }}</p>
        </template>
      </el-table-column>
      <el-table-column prop="addTime" label="失败时间" align="center">
        <template slot-scope="scope">
          <span>{{scope.row.failTime }}</span>
        </template>
      </el-table-column>

      <el-table-column v-if="checkPermission(['admin','YXUSEREXTRACT_ALL','YXUSEREXTRACT_EDIT','YXUSEREXTRACT_DELETE'])" label="操作" width="150px" align="center">
        <template slot-scope="scope">
            <el-button v-if="scope.row.status=='0'"
            v-permission="['admin','YXUSEREXTRACT_ALL','YXUSEREXTRACT_EDIT']"
            size="mini"
            type="primary"
            @click="edit(scope.row)"
          >审核</el-button>

          <el-button v-if="scope.row.status=='1'"
            v-permission="['admin','YXUSEREXTRACT_ALL','YXUSEREXTRACT_EDIT']"
            size="mini"
            type="danger"
            :loading="againLoading"
            @click="againPayment(scope.row.id)"
          >重新打款</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <el-pagination
      :total="total"
      :current-page="page + 1"
      style="margin-top: 8px;"
      layout="total, prev, pager, next, sizes"
      @size-change="sizeChange"
      @current-change="pageChange"
    />
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/crud'
import { del, againPaymentInfo } from '@/api/yxUserExtract'
import eForm from './form'
export default {
  components: { eForm },
  mixins: [initData],
  data() {
    return {
      delLoading: false,
      againLoading: false,
      queryTypeOptions: [
        { key: '-1', display_name: '-1-未通过' },
        { key: '0', display_name: '0-审核中' },
        { key: '1', display_name: '1-提现中' },
        { key: '2', display_name: '2-已到账' },
        { key: '3', display_name: '3-提现失败' }
      ]
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    checkPermission,
    beforeInit() {
      this.url = 'api/yxUserExtract'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      const type = query.type
      const value = query.value
      if (type && value) { this.params[type] = value }
      return true
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.dleChangePage()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    },
    againPayment(id) {
      this.againLoading = true
      againPaymentInfo({"id":id}).then(res => {
        this.againLoading = false
        this.init()
        this.$notify({
          title: '操作成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.againLoading = false
        console.log(err.response.data.message)
      })
    },
    add() {
      this.isAdd = true
      this.$refs.form.dialog = true
    },
    edit(data) {
      this.isAdd = false
      const _this = this.$refs.form
      _this.form = {
        id: data.id,
        uid: data.uid,
        realName: data.realName,
        extractType: data.extractType,
        bankCode: data.bankCode,
        bankAddress: data.bankAddress,
        alipayCode: data.alipayCode,
        extractPrice: data.extractPrice,
        mark: data.mark,
        balance: data.balance,
        failMsg: data.failMsg,
        failTime: data.failTime,
        addTime: data.addTime,
        status: data.status,
        wechat: data.wechat
      }
      _this.dialog = true
    }
  }
}
</script>

<style scoped>

</style>
